/*     */ package com.finir.finknjig.forms.controllers;
/*     */ 
/*     */ import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

import com.finir.finknjig.domain.Konto;
import com.finir.finknjig.forms.AnalitikaDva;
import com.finir.finknjig.persistence.hibernate.HibernatePersistenceManager;
import com.finir.finknjig.reports.jasper.ReportsVariables;
import com.finir.finknjig.reports.jasper.Stampanje;
import com.finir.finknjig.service.NalogFacade;
/*     */ 
/*     */ public class AnalitikaDvaController
/*     */   implements FocusListener
/*     */ {
/*     */   private AnalitikaDva form;
/*     */   private HibernatePersistenceManager pm;
/*     */   private NalogFacade facade;
/*     */ 
/*     */   public AnalitikaDvaController(AnalitikaDva form)
/*     */   {
/*  29 */     this.form = form;
/*  30 */     this.pm = new HibernatePersistenceManager();
/*  31 */     this.facade = new NalogFacade();
/*  32 */     form.getKontoodComboBox2().addFocusListener(this);
/*  33 */     form.getKontodojComboBox3().addFocusListener(this);
/*     */ 
/*  35 */     fillCombos();
/*     */   }
/*     */ 
/*     */   private void prikaziPorukuZaPrazanuListu() {
/*  39 */     JOptionPane.showMessageDialog(this.form, 
/*  40 */       "Ni jedan nalog nije evidentiran u tom periodu!", "Info", 
/*  41 */       1);
/*     */   }
/*     */ 
/*     */   public void fillCombos() {
/*  45 */     List<Konto> k = this.pm.getAll(Konto.class);
/*  46 */     Collections.sort(k);
/*  47 */     DefaultComboBoxModel c3 = (DefaultComboBoxModel)this.form
/*  48 */       .getKontoodComboBox2().getModel();
/*  49 */     c3.removeAllElements();
/*  50 */     c3.addElement("");
/*     */ 
/*  52 */     for (Konto p : k) {
/*  53 */       c3.addElement(p);
/*     */     }
/*     */ 
/*  56 */     DefaultComboBoxModel c2 = (DefaultComboBoxModel)this.form
/*  57 */       .getKontodojComboBox3().getModel();
/*  58 */     c2.removeAllElements();
/*  59 */     c2.addElement("");
/*     */ 
/*  61 */     for (Konto p : k) {
/*  62 */       c2.addElement(p);
/*     */     }
/*     */ 
/*  65 */     k = null;
/*  66 */     System.gc();
/*     */   }
/*     */ 
/*     */   public void poKontu()
/*     */   {
/*  72 */     Date odDatum = this.form.getOddateChooserCombo1().getSelectedDate()
/*  73 */       .getTime();
/*     */ 
/*  75 */     Date doDatum = this.form.getDodateChooserCombo2().getSelectedDate()
/*  76 */       .getTime();
/*     */ 
/*  78 */     List nalozi = this.facade.vratiSveNalogeIzmedjuDatuma(odDatum, 
/*  79 */       doDatum);
/*     */ 
/*  81 */     if (nalozi.size() == 0) {
/*  82 */       prikaziPorukuZaPrazanuListu();
/*  83 */       return;
/*     */     }
/*     */ 
/*  86 */     Object konOd = this.form.getKontoodComboBox2().getSelectedItem();
/*  87 */     Object konDo = this.form.getKontodojComboBox3().getSelectedItem();
/*  88 */     Konto kontoOd = null;
/*  89 */     Konto kontoDo = null;
/*     */ 
/*  91 */     if (((konOd instanceof Konto) && (konDo instanceof Konto)) || (
/*  92 */       (konOd instanceof String) && (konDo instanceof String)))
/*     */     {
/*  94 */       if (konOd instanceof Konto) {
/*  95 */         kontoOd = (Konto)konOd;
/*     */       }
/*     */ 
/*  98 */       if (konDo instanceof Konto) {
/*  99 */         kontoDo = (Konto)konDo;
/*     */       }
/*     */ 
/* 102 */       Stampanje s = new Stampanje(this.form);
/*     */ 
/* 104 */       s.analitikaDva(nalozi, ReportsVariables.getPoKontu(), odDatum, 
/* 105 */         doDatum, kontoOd, kontoDo);
/*     */     } else {
/* 107 */       JOptionPane.showMessageDialog(this.form, 
/* 108 */         "Izaberite raspon konta ili ostavite oba prazna!", 
/* 109 */         "Upozorenje", 2);
/*     */     }
/* 111 */     nalozi = null;
/* 112 */     System.gc();
/*     */   }
/*     */ 
/*     */   public void focusGained(FocusEvent e)
/*     */   {
/* 118 */     if (e.getSource() instanceof JComboBox)
/* 119 */       ((JComboBox)e.getSource()).showPopup();
/*     */   }
/*     */ 
/*     */   public void focusLost(FocusEvent arg0)
/*     */   {
/*     */   }
/*     */ }


